package com.testes.umov.sync;

import java.util.List;

import com.testes.umov.R;
import com.testes.umov.model.TestData;

import android.R.color;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LogAdapter extends ArrayAdapter<TestData> {

	private int layoutResourceId;
	private Activity activity;
	private List<TestData> results;
	
	public LogAdapter(Activity activity, int resource, int textViewResourceId, List<TestData> results) {
		super((Context)activity, resource, textViewResourceId, results);
		this.activity = activity;
		this.results = results;
		this.layoutResourceId = R.layout.activity_sync_test_list_row;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		
		if(row == null) 
		{
			LayoutInflater inflater = this.activity.getLayoutInflater();
			row = inflater.inflate(this.layoutResourceId, parent, false);
			row.setBackgroundColor(color.background_dark);				
		}
		else 
		{
			TextView textView = (TextView)row.findViewById(R.id.listSync_textView);
			textView.setText(results.get(position).getDescription());
		}
		
		return row;
	}
	
	public void addData(TestData data) {
		this.results.add(data);
		notifyDataSetChanged();
	}

}
